home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Electro GIG
/
Electro GIG.iso
/
gig
/
gig.ins
< prev
next >
Wrap
Text File
|
1995-09-12
|
19KB
|
777 lines
#!/bin/csh -f
#
# %W% %E%
#
# giginstall: install gig software from tape or CDROM
#
# This script installs gig software under a user account on sun or sgi.
# It searches for an existing user account, its home directory and its
# group or creates these when necessary.
# It examines accounts local to the current host only.
# It assumes that the gig software is on a tape that has been loaded in
# the tape drive.
# It checks for sufficient disk space by comparing the value space_reqd
# that is patched in this file by maketape against the available space.
# Disk space is expected in the host's local units (i.e. Kb for sun,
# 1/2 Kb blocks for sgi). Utility "maketape" should take care of this.
#
# options:
# -v display installation status information (verbose)
# -f specify filename for tar command
# -o don't check on space_reqrd
#
# This script can only be run by root.
# Whenever a question is answered with 'q' the program will abort.
#
# check if user is root
set id_line = `id | grep 'root'`
if ("$id_line" == '') then
set probl_no = 1
goto problem
endif
# make sure path contains necessary directories
set path = (/usr/bsd /usr/ucb /bin /usr/bin /etc /usr/etc $path)
rehash
set cd_file = "gig.tar"
set cd_root = $cwd
# which machine is this script running on
set MACHINE = `uname -m`
switch ($MACHINE)
case IP[0-9]:
case IP[0-9][0-9]:
case IP[0-9][0-9][0-9]:
set machine = 'sgi'
set nr_tape = "/dev/nrtape"
set disk_free = 'df'
breaksw;
case 'sun':
case 'sun4':
case 'sun4[a-z0-9]':
set machine = 'sun'
set nr_tape = "/dev/nrst0"
set disk_free = 'df'
breaksw;
case 9000/7[0-9][0-9]:
set machine = 'hp'
set nr_tape = "/dev/rmt/0mn"
set disk_free = 'bdf'
breaksw;
default:
set probl_no = 2
goto problem
endsw
if( -e $cd_file) then
set nr_tape = $cd_root/$cd_file
endif
# set machine dependent default user directory
switch ($machine)
case 'sgi':
set fixd_def_dir = "/usr/people/"
breaksw
case 'sun':
set fixd_def_dir = "/export/home/"
breaksw
case 'hp':
set fixd_def_dir = "/users/"
breaksw
default:
set probl_no = 3
goto problem
endsw
# default names, files
set def_usr_name = 'gig'
set def_grp_name = 'giguser'
set def_usr_dir = "${fixd_def_dir}${def_usr_name}"
set def_ser_no = '9530'
set def_ser_name = 'gigrendermanager'
set def_ser_prot = '/tcp'
set pwd_file = /etc/passwd
set grp_file = /etc/group
set ser_file = /etc/services
# check passwd file, group file, services file
if !(-e $pwd_file) then
set probl_no = 4
goto problem
endif
if !(-e $grp_file) then
set probl_no = 5
goto problem
endif
if !(-e $ser_file) then
set probl_no = 17
goto problem
endif
set gigvrbos = 0
set gigdemo = 0
set checksiz = 1
set instfiles=
while ($#argv > 0)
set tmp=$1
shift argv
if ("-f" == "$tmp" ) then
# if parameter starts with slash it will be a device or a file specified
# with an absolute pathname, if colon this is probably a remote device
# like guest@machine:/dev/tape
# otherwise combine with current directory
# because we will changedir to the installation directory
if ((`echo $1 | grep '^/' ` == $1) ||(`echo $1 | grep ':' ` == $1)) then
set nr_tape=$1
else
set nr_tape=$cwd/$1
endif
echo "tarring from: " $nr_tape
shift
else if ("-i" == "$tmp" ) then
set instfiles=($instfiles $1)
shift
else if ("-o" == "$tmp" ) then
set checksiz = 0
else if ("-v" == "$tmp" ) then
set gigvrbos = 1
endif
end
if ( -f $cd_root/$cd_file && -f $cd_root/$machine$cd_file ) then
set extract="tar -xovf $cd_root/$cd_file;tar -xovf $cd_root/$machine$cd_file"
else
set extract = "tar -xovf $nr_tape"
endif
set def_instl_string = ("Default Installation y/n [y]: ")
set def_updat_string = ("Update existing GIG? y/n [y]: ")
set instl_string = ("Install? y/n [y]: ")
set usr_name = $def_usr_name
set grp_name = $def_grp_name
set usr_dir = $def_usr_dir
set ser_no = $def_ser_no
set first_time = 1
set ok = 'n'
while ( "$ok" == 'n' )
set grp_found = 0
set read_rest_later = 0
set chk_grp_later = 0
set found_gid = 0
set found_uid = 0
if ( $first_time ) then
# search for user in password file (do not ask)
set pwd_line = "`egrep "^${usr_name}:" $pwd_file`"
if !($status) then #found entry in passwd file
set read_rest_later = 1
if ($gigvrbos) echo "user $usr_name exists"
endif
else
# ask for user name
set old_usr_name = $usr_name
echo ""
echo -n "Enter user name [$def_usr_name]: "
set tmp = $<
if ("$tmp" != '') then
set usr_name = "$tmp"
else
set usr_name = "$def_usr_name"
endif
# search for user in password file
set pwd_line = "`egrep "^${usr_name}:" $pwd_file`"
if !($status) then #found entry in passwd file
set read_rest_later = 1
if ($gigvrbos) echo "user $usr_name exists"
else
# ask for group name and home directory
# ask for group name
echo -n "Enter group name [$def_grp_name]: "
set tmp = $<
if ("$tmp" != '') then
set grp_name = "$tmp"
else
set grp_name = "$def_grp_name"
endif
set chk_grp_later = 1
# ask for home directory
# substitute new user name in default directory
set def_dir = "$fixd_def_dir$usr_name"
echo -n "Enter home directory [$def_dir]: "
set tmp = $<
if ("$tmp" != '') then
set usr_dir = "$tmp"
else
set usr_dir = "$def_dir"
endif
endif
endif
if ($read_rest_later) then
# get home directory, gid and uid from pwd_file
set tmp = `echo "$pwd_line" | awk '{FS=":"; print $6}'`
if ( "$tmp" != '') then #found home directory
set usr_dir = "$tmp"
else
set probl_no = 6
goto problem
endif
# get gid
set tmp = `echo "$pwd_line" | awk '{FS=":"; print $4}'`
if ( "$tmp" != '') then #found group id
set grp_number = "$tmp"
set found_gid = 1
# get group name from group file via gid
set grp_line = "`egrep '^.*:.*:'${grp_number}':' $grp_file`"
if ( ! $status ) then #found entry in group file
set tmp = `echo "$grp_line" | awk '{FS=":"; print $1}'`
if ("$tmp" != '') then #found group name via groupid
set grp_name = "$tmp"
if ($gigvrbos) echo "gid of $grp_name = $grp_number"
else
set probl_no = 7
goto problem
endif
else
set probl_no = 15
goto problem
endif
else
set probl_no = 8
goto problem
endif
#get uid
set tmp = `echo "$pwd_line" | awk '{FS=":"; print $3}'`
if ( "$tmp" != '') then #found user id
set usr_number = "$tmp"
set found_uid = 1
if ($gigvrbos) echo "uid of $usr_name = $usr_number"
else
set probl_no = 9
goto problem
endif
if ! ($first_time) then
echo "group = $grp_name"
echo "home directory = $usr_dir"
endif
endif
echo ""
if (-f $usr_dir/bin/gig) then
echo -n "$def_updat_string"
else
if ($usr_name == $def_usr_name && \
$usr_dir == $def_usr_dir && \
$grp_name == $def_grp_name ) then
echo -n "$def_instl_string"
else
echo -n "$instl_string"
endif
endif
# get answer
set ok = $<
if ( $machine == hp ) then
set ok = `echo "$ok" | awk ' \
{ \
a = substr( $0, 1, 1);\
if ((a == "n") || (a == "N")) print "n"; else {\
if ((a == "q") || (a == "Q")) print "q"; else print "y" }\
}'`
else
set ok = `echo "$ok" | awk ' \\\
{ \\\
a = substr( $0, 1, 1);\\\
if ((a == "n") || (a == "N")) print "n"; else {\\\
if ((a == "q") || (a == "Q")) print "q"; else print "y" }\\\
}'`
endif
if ($first_time) set first_time = 0
if ($ok == 'q') then
echo ""
echo "installation aborted"
exit 0
endif
end
echo ""
unset ok
# check if services is available
set services_ok = 0
set first_service_time = 1
while !($services_ok)
set new_serno_needed = 0
set add_service_line = 1
set services_line = "`egrep ${ser_no} ${ser_file}`"
if !($status) then
set tmp_sname = `echo "$services_line" | awk '{print $1}'`
if ( $tmp_sname != $def_ser_name ) then
set new_serno_needed = 1
else
set add_service_line = 0
endif
else
if ( -x /usr/bin/ypcat ) then
set services_line = "`ypcat services | grep ${ser_no}`"
if !($status) then
set tmp_no = `echo "$services_line" | awk '{print $1}'`
if ( $tmp_no != $def_ser_name ) then
set new_serno_needed = 1
else
set add_service_line = 0
endif
endif
endif
endif
echo ""
if ($first_service_time) then
if !($new_serno_needed) then
echo "The RenderManager requires a specific port number to"
echo "run. Only change services port number if necessary."
echo -n "Enter port number [$def_ser_no]: "
set tmp = $<
if ("$tmp" != '') then
set ser_no = "$tmp"
else
set ser_no = "$def_ser_no"
set services_ok = 1
endif
else
echo "Port $ser_no is already in use."
echo -n "Enter new port number between 5000 and 9999: "
set tmp = $<
if ("$tmp" != '') set ser_no = "$tmp"
endif
else
if ($new_serno_needed) then
echo "Port ${ser_no} is already in use!"
echo -n "Enter new port number between 5000 and 9999: "
set tmp = $<
if ("$tmp" != '') set ser_no = "$tmp"
else
set services_ok = 1
endif
endif
if ($first_service_time) set first_service_time = 0
end
echo "Installing software"
#create user directory
if (-e $usr_dir) then
if !(-d $usr_dir) then
set probl_no = 11
goto problem
endif
if ($gigvrbos) echo "directory $usr_dir exists and is ok"
else
mkdir -p $usr_dir
if ($status) then
set probl_no = 12
goto problem
endif
set newdir # to remove in case of error
if ($gigvrbos) echo "created directory $usr_dir"
endif
# check for sufficient disk space;
# use second last column of 'df'
set df_free = `$disk_free $usr_dir | egrep '/' | awk '{print $(NF-2)}'`
if ($machine == 'sgi') then
set space_reqd = 61000
else
set space_reqd = 23000
endif
set status = 0
if (space_reqd == 777) then
set probl_no = 13
goto problem
endif
if (($checksiz == 1) && ($df_free < $space_reqd)) then
set probl_no = 14
goto problem
else
if ($gigvrbos) then
switch ($machine)
case "sgi":
echo "$df_free 1/2 Kb blocks free, enough to install $space_reqd"
breaksw
case "sun":
case "dec":
case "hp":
echo "$df_free Kb free, enough to install $space_reqd"
breaksw
endsw
endif
endif
if ($chk_grp_later) then
# search for existing group
if ($gigvrbos) echo "searching $grp_file for $grp_name..."
set grp_line = "`egrep "^${grp_name}:" $grp_file`"
if ( ! $status) then #found entry in group file
#get gid
set tmp = `echo "$grp_line" | awk '{FS=":"; print $3}'`
if ( "$tmp" != '') then #found group id
set grp_number = "$tmp"
set found_gid = 1
else
set probl_no = 10
goto problem
endif
if ($gigvrbos) echo "gid of $grp_name = $grp_number"
else
set found_gid = 0
# set probl_no = 16
# goto problem
endif
endif
if !($found_gid) then
# a new gid is required;
# search for first free gid and put it in group file
if ($gigvrbos) echo "creating new gid for $grp_name..."
set new_nu = 999
while (1)
@ new_nu ++
egrep -s "^.*:.*:.*:$new_nu" $pwd_file
if ($status) then
set grp_number = $new_nu
unset new_nu
if ($gigvrbos) echo new gid $grp_number
break
else
if ($gigvrbos) echo gid $new_nu not free
endif
end
#keep old group file
set old_grp_file = ${grp_file}.gig
#?????
if !(-f $old_grp_file) then
/bin/mv $grp_file $old_grp_file #maintain old date for original file
/bin/cp $old_grp_file $grp_file
if ( $machine == hp ) then
chmod 444 $grp_file
endif
set grpfile_chgd
endif
unset old_grp_file
# append new line to group file
set doe = "echo ${grp_name}::${grp_number}:"
$doe >> $grp_file
if ($status) then
echo "cannot write $grp_file"
else
if ($gigvrbos) echo "added new group $grp_name to $grp_file"
endif
endif
if !($found_uid) then
# a new uid is required;
# search for first free uid and put it in passwd file
if ($gigvrbos) echo "creating new uid for $usr_name..."
set new_nu = 999
set found = 1
while ($found)
@ new_nu ++
egrep -s "^.*:.*:$new_nu" $pwd_file > /dev/null
if ($status) then
set usr_number = $new_nu
unset new_nu
if ($gigvrbos) echo new uid $usr_number
break
else
if ($gigvrbos) echo uid $new_nu not free
endif
end
#keep old passwd file
set old_pwd_file = ${pwd_file}.gig
#?????
if !(-f $old_pwd_file) then
/bin/mv $pwd_file $old_pwd_file #maintain old date for original file
/bin/cp $old_pwd_file $pwd_file
if ( $machine == hp ) then
chmod 444 $pwd_file
endif
set pwdfile_chgd
endif
unset old_pwd_file
#append line to passwd file
set doe="echo ${usr_name}::${usr_number}:${grp_number}:ElectroGIG:${usr_dir}:/bin/csh"
$doe >> $pwd_file
if ($status) then
echo "cannot write $pwd_file"
else
if ($gigvrbos) echo "added new user $usr_name to $pwd_file"
endif
if (-e /usr/sbin/pwconv ) then
pwconv
endif
endif
#
# chgrp on another machine's disk may fail when done by root,
# therefore su
#
chown $usr_name $usr_dir
if ( $machine == hp ) then
chgrp $grp_name $usr_dir
else
su $usr_name -c "chgrp $grp_name $usr_dir"
endif
if ($gigvrbos) ls -ld $usr_dir
if ($add_service_line) then
/bin/cp $ser_file /etc/services.gig
set doe="echo ${def_ser_name} ${ser_no}${def_ser_prot} # ElectroGIG RenderManager"
$doe >> $ser_file
if ($status) then
echo "cannot write $ser_file"
else
if ($gigvrbos) echo "added new services $ser_no to $ser_file"
endif
endif
#
#list of dirs in a project and list of standard projects
#
set libdirs=(lib/intdump lib/intenv lib/intmap lib/intlib lib/intpixmap rcrd production)
set prjdirs=(intdump intenv intmap intlib rcrd production)
set prjs=(gig_prj)
#check if new project-structure is available, if not, make one
if (-e $usr_dir/.gigid) then
if (! -e $usr_dir/projects) then
su $usr_name -c "mkdir $usr_dir/projects"
foreach p ($prjs)
su $usr_name -c "mkdir -p $usr_dir/projects/$p"
end
foreach d ($prjdirs)
su $usr_name -c "mkdir -p $usr_dir/projects/gig_prj/$d"
end
set ld=($libdirs)
foreach d ($prjdirs)
if ($d != "intlib") then
su $usr_name -c "/bin/mv $usr_dir/$ld[1]/* $usr_dir/projects/gig_prj/$d >& /dev/null"
endif
shift ld
end
endif
endif
set rootfiles=(utils/setgamma)
foreach i ( $rootfiles )
if ( -e ~$usr_dir/$i ) then
chown $usr_name $usr_dir/$i
endif
end
su $usr_name -c "cd $usr_dir; find . -exec chmod u+w {} \;"
sleep 10
echo ""
# echo "Extracting software from tape"
if( ! (-f $nr_tape)) then # if not a plain file rewind
mt -t $nr_tape rewind
mt -t $nr_tape fsf 1
endif
su $usr_name -c "cd $usr_dir; $extract"
if( ! (-f $nr_tape)) then # if not a plain file rewind
mt -t $nr_tape rewind
endif
#set .rhosts for channels
if (-d $usr_dir/utils) then
su $usr_name -c "echo `hostname` $usr_name >! $usr_dir/utils/rhosts"
if ($gigvrbos) echo "created $usr_dir/utils/rhosts"
endif
if ($gigvrbos) echo "installing dotfiles:"
# move dotfiles to home dir after saving old files
set dotfiles = (login cshrc rhosts Xdefaults)
if ( $machine == sun ) then
set dotfiles = ($dotfiles openwin-init)
endif
if ( $machine == sgi ) then
set dotfiles = ($dotfiles sgisession Sgiresources)
endif
foreach f($dotfiles)
if (-f $usr_dir/utils/$f) then
if (-f $usr_dir/.$f) then
set newf = ${f}.$$
while (-f $usr_dir/$newf) # just in case ${f}.$$ exists
set newf = ${newf}.$$
end
/bin/mv $usr_dir/.$f $usr_dir/$newf
endif
/bin/mv $usr_dir/utils/$f $usr_dir/.$f
if ($gigvrbos) echo "$f installed"
endif
end
unset dotfiles
# check if the library project exists. If not create it and link
# it to the old intdump etc.
if (! -e $usr_dir/projects/library_prj) then
su $usr_name -c "mkdir -p $usr_dir/projects/library_prj"
foreach l ($libdirs)
su $usr_name -c "ln -s $usr_dir/$l $usr_dir/projects/library_prj"
end
endif
# install gig logo on sgi machine
switch ($machine)
case "sgi":
chkconfig -f visuallogin on
chkconfig -f noiconlogin off
# change owner of setgamma and make it set-owner-executable
foreach i ( $rootfiles )
if ( -f $usr_dir/$i ) then
#chown root $usr_dir/utils/setgamma
chown root $usr_dir/$i
chmod 4555 $usr_dir/$i
endif
end
breaksw
case "sun":
case "hp":
case "dec":
breaksw
endsw
foreach i ($instfiles)
#echo su $usr_name -c "cd $usr_dir ; $cd_root/$i.ins"
su $usr_name -c "cd $usr_dir ; /bin/csh $cd_root/$i.ins -c"
end
echo ""
echo GIG software installation ready
echo ""
echo ""
echo ""
su $usr_name -c "$usr_dir/utils/getid"
echo ""
endif
exit 0
problem:
echo ""
echo -n "installation problem: "
switch ($probl_no)
case "1"
echo "you should be logged in as 'root' to run $0"
breaksw
case "2"
echo "$0 running on unknown machine $MACHINE, bye"
breaksw
case "3"
echo "$0 needs help ($machine)"
breaksw
case "4"
echo "cannot find passwd file"
breaksw
case "5"
echo "cannot find group file"
breaksw
case "6"
echo "cannot obtain home dir for $usr_name from $pwd_file"
breaksw
case "7"
echo "cannot obtain group name for $grp_number from $grp_file"
breaksw
case "8"
echo "cannot obtain gid for $usr_name from $pwd_file"
breaksw
case "9"
echo "cannot obtain uid for $usr_name from $pwd_file"
breaksw
case "10"
echo "cannot obtain gid for $grp_name from $grp_file"
breaksw
case "11"
echo "existing $usr_dir is not a directory"
breaksw
case "12"
echo "cannot not create directory $usr_dir"
breaksw
case "13"
echo "required space not properly initialised"
breaksw
case "14"
echo "there is not enough disk space to install GIG at $usr_dir"
switch ($machine)
case "sgi":
echo " ($space_reqd blocks required)"
breaksw
case "sun":
case "dec":
echo " ($space_reqd Kb required)"
breaksw
endsw
breaksw
case "15"
echo "cannot find group number $grp_number in $grp_file"
breaksw
case "16"
echo "cannot find group name $grp_name in $grp_file"
breaksw
case "17"
echo "cannot find services file"
breaksw
default
breaksw
endsw
echo ""
echo "$0 aborted"
# undo as much as possible
# remove newly created directory
if ($?newdir) then
/bin/rm -rf $usr_dir
endif
# restore passwd and group files
if ($?pwdfile_chgd) then
/bin/rm -f $pwd_file
/bin/mv $old_pwd_file $pwd_file
endif
if ($?grpfile_chgd) then
/bin/rm -f $grp_file
/bin/mv $old_grp_file $grp_file
endif
exit $probl_no
#-----------------------------------------------------------------------